package com.xinlan.imageeditlibrary.editimage.utils;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;

import java.util.List;

public class Tools {

    public static Dialog getLoadingDialog(Context context, int titleId, boolean canCancel) {
        return getLoadingDialog(context, context.getString(titleId), canCancel);
    }

    public static Dialog getLoadingDialog(Context context, String title, boolean canCancel) {
        ProgressDialog dialog = new ProgressDialog(context);
        dialog.setCancelable(canCancel);
        dialog.setMessage(title);
        return dialog;
    }

    public static boolean isEmpty(List list) {
        if (list == null)
            return true;

        return list.size() == 0;
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }
}
